home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Objects / Server / serverObjectsCommon.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  10.1 KB  |  383 lines

  1. // Copyright 2002, 2003 Macromedia, Inc. All rights reserved.
  2.  
  3. // This file manages the behavior of the error dialog that appears when the
  4. // prerequisites are not met for applying a server object into the document.
  5. // The error dialog contains links to the appropriate dialogs in order to
  6. // meet the prerequisite conditions.
  7.  
  8.  
  9. //--------------------------------------------------------------------
  10. // FUNCTION:
  11. //   getSetupStepsForServerObject
  12. //
  13. // DESCRIPTION:
  14. //   Returns a javascript array, which represents the steps that
  15. //   need to be completed before a server object can be inserted
  16. //   into the document.
  17. //
  18. // ARGUMENTS:
  19. //   excludeRecordsetCreationStep - boolean - (optional) set to
  20. //     true to elimnate the recordset creation step
  21. //   bDynDataInstrOnly - boolean (optional) set to true for special
  22. //     case wording in instruction dialog for dynamic data steps.
  23. //
  24. // RETURNS:
  25. //   Array of strings
  26. //--------------------------------------------------------------------
  27.  
  28. function getSetupStepsForServerObject(excludeRecordsetCreationStep, bDynDataInstrOnly)
  29. {
  30.   var steps = new Array();
  31.   var dom = null;
  32.   var documentType = "";
  33.   var serverModel = "";
  34.  
  35.   // Try to get the server model of the currently open document.
  36.   // If there's no currently open document, get the default server
  37.   // model for the current site.
  38.   dom = dw.getDocumentDOM();
  39.   
  40.   // Try to get the site for the currently selected document
  41.   var url = "";
  42.   var curSite = null;
  43.   if (dom != null)
  44.     url = dom.URL;
  45.   if (url.length > 0)
  46.     curSite = site.getSiteForURL(url);
  47.   else
  48.     curSite = site.getCurrentSite(); 
  49.   if (curSite.length == 0)
  50.     curSite = site.getCurrentServerSite();
  51.   
  52.   if (dom == null)
  53.   {
  54.     dom = dw.getNewDocumentDOM();
  55.   }
  56.   
  57.   if (dom)
  58.   {
  59.     if (dom.documentType)
  60.     {
  61.       documentType = dom.documentType;
  62.     }
  63.     if (dom.serverModel)
  64.     {
  65.       serverModel = dom.serverModel.getFolderName();
  66.     }
  67.   }
  68.  
  69.   if (bDynDataInstrOnly)
  70.   {
  71.     // Special case starting text. See DynamicDataInstrOnly.htm.
  72.     steps.push(dw.loadString("insertbar/server/dynamicDataInstruction"));
  73.   }
  74.   else
  75.   {
  76.     steps.push(MM.MSG_BeforeInsertingServerObject);
  77.   }
  78.   if (curSite.length != 0 && site.getIsServerSite(curSite))
  79.      steps.push(dwscripts.sprintf(MM.MSG_CreateServer,'<a href="#" onMouseDown="event:CreateSite">','</a>'));
  80.   else
  81.      steps.push(dwscripts.sprintf(MM.MSG_CreateSite,'<a href="#" onMouseDown="event:CreateSite">','</a>'));
  82.   steps.push(dwscripts.sprintf(MM.MSG_ChooseDynamicDocType,'<a href="#" onMouseDown="event:SetDocType">','</a>'));
  83.   if (curSite.length != 0 && site.getIsServerSite(curSite))
  84.      steps.push(dwscripts.sprintf(MM.MSG_SetURLPrefix,'<a href="#" onMouseDown="event:CreateSite">','</a>'));
  85.   else
  86.       steps.push(dwscripts.sprintf(MM.MSG_SetAppServer,'<a href="#" onMouseDown="event:SetAppServer">','</a>'));
  87.  
  88.   if (documentType == "ColdFusion")
  89.   {
  90.     // ColdFusion specific steps are only for the DWMX version.
  91.     steps.push(dwscripts.sprintf(MM.MSG_SetRDSPassword,'<a href="#" onMouseDown="event:SetRDSPassword">','</a>'));
  92.     steps.push(dwscripts.sprintf(MM.MSG_CreateCFDataSource,'<a href="#" onMouseDown="event:CreateCFDataSource">','</a>'));
  93.   }
  94.   
  95.   if (!excludeRecordsetCreationStep)
  96.   {
  97.     var fmt = MM.MSG_CreateRecordset;
  98.       var before = '<a href="#" onMouseDown="onCreateRecordset()">';
  99.       var after = '</a>';
  100.       var recordsetDisplayName = dwscripts.getRecordsetDisplayName();
  101.     
  102.       steps.push(dwscripts.sprintf(fmt, before, recordsetDisplayName, after));
  103.   }
  104.  
  105.   if (documentType == "ASP.NET_CSharp" || documentType == "ASP.NET_VB")
  106.   {
  107.     // For ASP.NET, add an optional step specifying to deploy to the testing server bin.
  108.     steps[steps.length-1] += "<br><br>"
  109.                           + dwscripts.sprintf(MM.MSG_DeployToTestingServerBin,
  110.                                               '<a href="#" onMouseDown="site.showTestingServerBinDeployDialog()">','</a>'
  111.                                              );
  112.   }
  113.  
  114.   // The Instruction steps dialog has very little vertical space between the
  115.   //   last instruction and the bottom of the dialog. As a simple workaround, 
  116.   //   we add a <br> at the end of the last instructions text.
  117.   steps[steps.length - 1] += "<br>";
  118.   
  119.   return steps;
  120. }
  121.  
  122.  
  123. //--------------------------------------------------------------------
  124. // FUNCTION:
  125. //   setupStepsCompletedForServerObject
  126. //
  127. // DESCRIPTION:
  128. //   Returns an integer indication how many of the steps have been 
  129. //   completed.  A value of -1 indicates that all of the steps
  130. //   are complete.
  131. //
  132. // ARGUMENTS:
  133. //   excludeRecordsetCreationStep - boolean - (optional) set to
  134. //     true to elimnate the recordset creation step
  135. //
  136. // RETURNS:
  137. //   integer
  138. //--------------------------------------------------------------------
  139.  
  140. function setupStepsCompletedForServerObject(excludeRecordsetCreationStep)
  141. {
  142.   var dom = null;
  143.   var cfDsnList = null;
  144.   var connList = null;
  145.   var documentType = "";
  146.   var serverModel = "";
  147.   var url = "";
  148.   var curSite = null;
  149.   
  150.   // Try to get the site for the currently selected document
  151.   dom = dw.getDocumentDOM();
  152.   if (dom != null)
  153.   {
  154.     url = dom.URL;
  155.   }
  156.   
  157.   if (url.length > 0)
  158.   {
  159.     curSite = site.getSiteForURL(url);
  160.   }
  161.   else
  162.   {
  163.     curSite = site.getCurrentSite();
  164.   }
  165.   if (curSite.length == 0)
  166.     curSite = site.getCurrentServerSite();
  167.  
  168.   // If no site defined, prompt user to create one
  169.   if (curSite.length == 0)
  170.   {
  171.     return 0;
  172.   }
  173.  
  174.   // Try to get the server model of the currently selected document
  175.   if (dom == null)
  176.   {
  177.     dom = dw.getNewDocumentDOM();
  178.   }
  179.   if (dom)
  180.   {
  181.     if (dom.documentType)
  182.     {
  183.       documentType = dom.documentType;
  184.     }
  185.     if (dom.serverModel)
  186.     {
  187.       serverModel = dom.serverModel.getFolderName();
  188.     }
  189.   }
  190.  
  191.   // If doc type does not support server markup, prompt user
  192.   // to choose dynamic doc type
  193.   if (serverModel.length == 0)
  194.   {
  195.     return 1;
  196.   }
  197.  
  198.   // If no app server is defined, prompt user to specify one
  199.   if (dom.serverModel.testAppServer() == false)
  200.   {
  201.     return 2;
  202.   }
  203.  
  204.   if (documentType == "ColdFusion")
  205.   {
  206.     // ColdFusion specific steps are only for the DWMX version.
  207.  
  208.     // Getting the DSN list updates the flag indicating whether we
  209.       // need to prompt for RDS info.
  210.     cfDsnList = MMDB.getColdFusionDsnList();
  211.  
  212.     // If RDS password is empty, prompt user to supply one
  213.     if (MMDB.needToPromptForRdsInfo(true))
  214.     {
  215.       return 3;
  216.     }
  217.  
  218.     // If no CF data sources are defined, send user to CF Administrator
  219.     if (cfDsnList == null || cfDsnList.length == 0)
  220.     {
  221.       return 4;
  222.     }
  223.     
  224.     // If no recordsets are defined, then send user to recordset sb
  225.     if (!excludeRecordsetCreationStep && !recordsetIsDefined())
  226.     {
  227.       return 5;
  228.     }
  229.   }
  230. /*//The deploy instruction for asp.net is optional...
  231.   else if (documentType == "ASP.NET_CSharp" || documentType == "ASP.NET_VB")
  232.   {
  233.     // If ASCX files have not yet been deployed, send user to deploy dialog
  234.     if (site.getNeedToDeployTestingServerBin())
  235.     {
  236.       return 3;
  237.     }
  238.  
  239.     // If no recordsets are defined, then send user to recordset sb
  240.     if (!excludeRecordsetCreationStep && !recordsetIsDefined())
  241.     {
  242.       return 4;
  243.     }
  244.   }
  245. */
  246.   else
  247.   {   
  248.     // If no recordsets are defined, then send user to recordset sb
  249.     if (!excludeRecordsetCreationStep && !recordsetIsDefined())
  250.     {
  251.       return 3;
  252.     }
  253.   }
  254.  
  255.   // All setup steps have been completed
  256.   return -1;
  257. }
  258.  
  259.  
  260.  
  261. //--------------------------------------------------------------------
  262. // FUNCTION:
  263. //   onCreateRecordset
  264. //
  265. // DESCRIPTION:
  266. //   Handles event that user clicked the create recordset instruction step.
  267. //
  268. // ARGUMENTS:
  269. //   none
  270. //
  271. // RETURNS:
  272. //   boolean
  273. //--------------------------------------------------------------------
  274.  
  275. function onCreateRecordset()
  276. {
  277.   // Only popup the recordset dialog if the document has a server model.
  278.   if (dwscripts.hasServerModel())
  279.   {
  280.     saveBodyRelativeSelection();
  281.     dw.popupServerBehavior("Recordset.htm");
  282.     restoreBodyRelativeSelection();
  283.   }
  284. }
  285.  
  286.  
  287. //--------------------------------------------------------------------
  288. // FUNCTION:
  289. //   recordsetIsDefined
  290. //
  291. // DESCRIPTION:
  292. //   Returns true if a recordset is currently defined on the page
  293. //
  294. // ARGUMENTS:
  295. //   none
  296. //
  297. // RETURNS:
  298. //   boolean
  299. //--------------------------------------------------------------------
  300.  
  301. function recordsetIsDefined()
  302. {
  303.   var retVal = false;
  304.   
  305.   var rsList = dwscripts.getRecordsetNames();
  306.   if (rsList && rsList.length > 0)
  307.   {
  308.     retVal = true;
  309.   }
  310.   
  311.   return retVal;
  312. }
  313.  
  314.  
  315.  
  316. //--------------------------------------------------------------------
  317. // FUNCTION:
  318. //   saveBodyRelativeSelection
  319. //
  320. // DESCRIPTION:
  321. //   Stores the body tag relative location of the current selection
  322. //   in the global variable CURRENT_SEL.
  323. //
  324. // ARGUMENTS:
  325. //   none
  326. //
  327. // RETURNS:
  328. //   nothing
  329. //--------------------------------------------------------------------
  330.  
  331. var CURRENT_SEL = null;
  332.  
  333. function saveBodyRelativeSelection()
  334. {
  335.   var dom = dw.getDocumentDOM();
  336.   
  337.   var sel = dom.getSelection();
  338.   
  339.   if (sel && sel.length > 1)
  340.   {
  341.     var bodyOffset = dom.nodeToOffsets(dom.body);
  342.  
  343.     sel[0] = sel[0] - bodyOffset[0];
  344.     sel[1] = sel[1] - bodyOffset[0];
  345.     
  346.     CURRENT_SEL = sel;
  347.   }  
  348. }
  349.  
  350.  
  351. //--------------------------------------------------------------------
  352. // FUNCTION:
  353. //   restoreBodyRelativeSelection
  354. //
  355. // DESCRIPTION:
  356. //   Sets the selection back to it's original location, before the
  357. //   recordset was inserted.
  358. //
  359. // ARGUMENTS:
  360. //   none
  361. //
  362. // RETURNS:
  363. //   nothing
  364. //--------------------------------------------------------------------
  365.  
  366. function restoreBodyRelativeSelection()
  367. {
  368.   var sel = CURRENT_SEL;
  369.   CURRENT_SEL = null;
  370.   
  371.   if (sel)
  372.   {
  373.     var dom = dw.getDocumentDOM();
  374.     
  375.     var bodyOffset = dom.nodeToOffsets(dom.body);
  376.     
  377.     sel[0] = sel[0] + bodyOffset[0];
  378.     sel[1] = sel[1] + bodyOffset[0];
  379.     
  380.     dom.setSelection(sel[0], sel[1]);
  381.   }
  382. }
  383.